package com.woniuxy.hrp.service.Serviceimpl;

import com.woniuxy.hrp.entity.*;
import com.woniuxy.hrp.entity.DoctorAndTime;
import com.woniuxy.hrp.entity.Doctor;
import com.woniuxy.hrp.entity.DoctorAndTime;
import com.woniuxy.hrp.mapper.ArrangeTimeMapper;
import com.woniuxy.hrp.mapper.DoctorAndTimeMapper;
import com.woniuxy.hrp.mapper.DoctorMapper;
import com.woniuxy.hrp.service.DoctorAndTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DoctorAndTimeServiceImpl implements DoctorAndTimeService {

    @Autowired
    private DoctorAndTimeMapper doctorAndTimeMapper;

    @Autowired
    private DoctorMapper doctorMapper;

    @Autowired
    private ArrangeTimeMapper arrangeTimeMappeer;

    //新增医生值班
    @Override
    public void add(AdminDoctorAndTime doctorAndTime, ArrangeTime arrangeTime) {
            arrangeTimeMappeer.myinsert(arrangeTime);
            doctorAndTime.setArrangeTimeId(arrangeTime.getId());
            doctorAndTime.setStatus("y");
            doctorAndTimeMapper.myinsert(doctorAndTime);

    }

    //修改医生值班
    @Override
    public void update(AdminDoctorAndTime doctorAndTime, ArrangeTime arrangeTime) {
        arrangeTimeMappeer.myinsert(arrangeTime);
        doctorAndTime.setArrangeTimeId(arrangeTime.getId());
        doctorAndTimeMapper.updateByCondition(doctorAndTime);

    }

    //根据医生id查询医生排班信息
    @Override
    public List<DoctorAndTime> findById(int id) {
        List<DoctorAndTime> doctorAndTimes = doctorAndTimeMapper.findById(id);
        return doctorAndTimes;
    }

    //调班申请
    @Override
    public void applyfor(Application application) {
        doctorAndTimeMapper.applyfor(application);
    }

    //查询调班申请
    @Override
    public List<DoctorAndTime> findApplyfor() {
        List<DoctorAndTime> doctorAndTimes = doctorAndTimeMapper.findApplyfor();
        return doctorAndTimes;
    }

    //同意调班
    @Override
    public void agree(int id) {
        AdminDoctorAndTime adminDoctorAndTime = doctorAndTimeMapper.findApplyforinfo(id);
        adminDoctorAndTime.setArrangeTimeId(adminDoctorAndTime.getNewarrangeTimeId());
        doctorAndTimeMapper.agree(adminDoctorAndTime);
    }

    //拒绝调班
    @Override
    public void refuse(int id) {
        AdminDoctorAndTime adminDoctorAndTime = new AdminDoctorAndTime();
        adminDoctorAndTime.setId(id);
        adminDoctorAndTime.setStatus("y");
        doctorAndTimeMapper.updateByCondition(adminDoctorAndTime);
    }

    //删除医生所有值班
    @Override
    public void delete(int id) {
        doctorAndTimeMapper.updataStatus(id);
    }

    //根据主键id查询排班信息
    @Override
    public DoctorAndTime findByFid(int id) {
        DoctorAndTime doctorAndTime = doctorAndTimeMapper.findByFid(id);
        return doctorAndTime;
    }

    //排班前查询所有医生
    @Override
    public List<Doctor> findAllDoctor() {
        List<Doctor> doctors = doctorMapper.selectAll();
        return doctors;
    }
    @Override
    public DoctorAndTime seleById(int id) {
      return doctorAndTimeMapper.seleById(id);
    }

}
